<template>
  <a-modal title="积分余额" :after-close="reset" @ok="submit">
    <a-form ref="formRef" :model="form" :rules="rules" :label-col="{ style: { width: '80px' } }">
      <a-form-item label="修改余额" name="moneyType">
        <a-radio-group v-model:value="form.moneyType">
          <a-radio :value="1"> 增加 </a-radio>
          <a-radio :value="2"> 减少 </a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="余额" name="moneyValue">
        <a-input-number v-model:value="form.moneyValue" placeholder="url" />
      </a-form-item>
      <a-form-item label="修改积分" name="integralType">
        <a-radio-group v-model:value="form.integralType">
          <a-radio :value="1"> 增加 </a-radio>
          <a-radio :value="2"> 减少 </a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="积分" name="integralValue">
        <a-input-number v-model:value="form.integralValue" placeholder="url" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup lang="ts">
import { foundsApi } from "./api";
import { validReg } from '@/utils/validate';
import type { Iuser } from "./entity";

const props = withDefaults(defineProps<{
  data: Partial<Iuser>
}>(), {
})
const { formRef, submit, close } = useDialog({ validCallback: save })

let form = $ref({ uid: 0, moneyType: 1, moneyValue: 0, integralType: 1, integralValue: 0 })
watchEffect(() => {
  if (props.data) {
    form.uid = props.data.uid as number

  }
})

const rules = {
  usergroupName: [validReg('required', '请输入用户名')]
}

onMounted(() => {
})

const emit = defineEmits(['change'])

function save() {
  foundsApi(form).then(() => {
    AntMessage.success('保存成功')
    close()
    emit('change')
  })
}

function reset() {
  form = { uid: 0, moneyType: 1, moneyValue: 0, integralType: 1, integralValue: 0 }
}
</script>

<style lang="less"></style>
